from django.contrib.auth.models import AbstractUser
from django.db import models


class Users(AbstractUser):
    id = models.CharField('id', max_length=64, primary_key=True)
    name = models.CharField("name", max_length=256)
    username = models.CharField("user name", max_length=150)
    sex = models.CharField("sex", max_length=1, default=1)  # woman 1 man 0
    birthday = models.DateField("birthday", blank=True, null=True)
    mail = models.EmailField("mail", max_length=50, blank=True, null=True)
    phone = models.CharField("phone", max_length=20, blank=True, null=True)
    openid = models.CharField("openid", max_length=150, blank=True, null=True)
    chef = models.CharField("chef", max_length=150, blank=True, null=True)

    # 解决groups冲突
    groups = models.ManyToManyField(
        'auth.Group',
        verbose_name='groups',
        blank=True,
        related_name='custom_user_groups'  # 添加related_name以避免冲突
    )

    # 解决user_permissions冲突
    user_permissions = models.ManyToManyField(
        'auth.Permission',
        verbose_name='user permissions',
        blank=True,
        related_name='custom_user_permissions'  # 添加related_name以避免冲突
    )

    def __str__(self):
        return self.name

    class Meta:
        default_permissions = ()
        verbose_name = "user"
        verbose_name_plural = "users"
